<template>
	<form-container title="添加" :width="550" :visible="visible" :destroy-on-close="true" @close="onClose">
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="检验编码：" name="code">
				<a-input v-model:value="formData.code" disabled="false" placeholder="请输入主题" allow-clear />
			</a-form-item>
		</a-form>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="检验名称：" name="name">
				<a-input v-model:value="formData.name" placeholder="请输入主题" allow-clear />
			</a-form-item>
		</a-form>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="描述：" name="description">
				<a-input v-model:value="formData.description" placeholder="请输入主题" allow-clear />
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="sendLoading">发送</a-button>
		</template>
	</form-container>
	<user-selector-plus ref="UserSelectorPlus" :org-tree-api="selectorApiFunction.orgTreeApi"
		:user-page-api="selectorApiFunction.userPageApi" :checked-user-list-api="selectorApiFunction.checkedUserListApi"
		@onBack="userBack" />
</template>

<script setup name="messageForm">
import { required } from '@/utils/formRules'
import { message } from 'ant-design-vue'
import jindesapi from '@/api/mes/basicdata/jindesapi'
import userSelectorPlus from '@/components/Selector/userSelectorPlus.vue'
import tool from '@/utils/tool'
import userCenterApi from '@/api/sys/userCenterApi'
import userApi from '@/api/sys/userApi'

const sendLoading = ref(false)
let UserSelectorPlus = ref()
// 定义emit事件
const emit = defineEmits({ successful: null })
// 默认是关闭状态
let visible = ref(false)
const formRef = ref()
// 表单数据
const formData = ref({})

// 打开抽屉
const onOpen = () => {
	visible.value = true
	formData.value = {}
}
// 关闭抽屉
const onClose = () => {
	emit('successful')
	visible.value = false
}




// 验证并提交数据
const onSubmit = () => {
	formRef.value.validate().then(() => {

		jindesapi
			.jinesAdd(formData.value)
			.then(() => {
				message.success('发送成功')
				onClose()
			})
			.finally(() => {
				sendLoading.value = false
			})
	})
}

// 传递设计器需要的API
const selectorApiFunction = {
	orgTreeApi: (param) => {
		return workshopApi.workAdd(param).then((data) => {
			return Promise.resolve(data)
		})
	}
}
// 调用这个函数将子组件的一些数据和方法暴露出去
defineExpose({
	onOpen
})
</script>
